package example.test;

import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.filefilter.DirectoryFileFilter;
import org.apache.commons.io.filefilter.TrueFileFilter;
import org.junit.Test;

import java.io.File;
import java.util.Collection;
import java.util.LinkedList;

public class YASUO {

    @Test
    public void test1() {
        File file = FileUtils.getFile("C:/Users/yangyang/Desktop/YASUO/ideaIC-2021.3.win");

        //递归获取所有文件和目录
        Collection<File> filesAndDirs = FileUtils.listFilesAndDirs(file, TrueFileFilter.INSTANCE, DirectoryFileFilter.DIRECTORY);
        int size1 = filesAndDirs.size();
        System.out.println(size1);
//        C:\IDEA\ideaIU-2019.3.5-jbr8.win
        LinkedList<String> list21 = new LinkedList<>();
        for (File andDir : filesAndDirs) {
            if (andDir.isFile()) {
                list21.add(andDir.getName());
            }
        }

        File file2019 = FileUtils.getFile("C:/IDEA/ideaIU-2019.3.5-jbr8.win");
        Collection<File> files = FileUtils.listFilesAndDirs(file2019, TrueFileFilter.INSTANCE, DirectoryFileFilter.DIRECTORY);
        System.out.println(files.size());

        LinkedList<String> list19 = new LinkedList<>();
        for (File andDir : files) {
            if (andDir.isFile()) {
                list19.add(andDir.getName());
            }
        }
        //交集 intersection
        Collection<String> intersection = CollectionUtils.intersection(list19, list21);

        //4、差集（扣除）
        Collection<String> subtract = CollectionUtils.subtract(list19, list21);

        System.out.println("交集=" + intersection.size());
        System.out.println("差集=" + subtract.size());
    }


}
